home *** CD-ROM | disk | FTP | other *** search
- // Matrix Pallette
- static const int MAX_MATRICES = 23;
- float4x3 WorldMatrixArray[MAX_MATRICES] : WORLDMATRIXARRAY;
- float4x4 ViewProjection;// : VIEWPROJECTION;
- float4x4 WorldMatrix;
- float4x4 ShadowViewProjection;
- float4x4 TextureMatrix;
- float4x4 ViewIT;
-
- texture DiffuseTexture;
- texture ShadowTexture;
- texture FogOfWar;
-
- float3 LightDirection = {0.0f, 0.0f, -1.0f }; //light Direction
- float3 SunColor = { 1., 0.86, .70 };
- float3 Ambient = { 0.24, 0.12, 0.04 };
- float4 ZBias = { 0.0, 0.0, 0.0, -0.003 };
- float4 ShadowOffset;
- float4 BlinkFactor = { 0.4, 0.4, 0.4, 0.4 };
-
- ///////////////////////////////////////////////////////
- struct VS_INPUT
- {
- float4 Pos : POSITION;
- float4 BlendWeights : BLENDWEIGHT;
- float4 BlendIndices : BLENDINDICES;
- float3 Normal : NORMAL;
- float3 Tex0 : TEXCOORD0;
- };
-
- struct VS_OUTPUT
- {
- float4 Pos : POSITION;
- float4 Diffuse : COLOR;
- float2 Tex0 : TEXCOORD0;
- float2 Tex1 : TEXCOORD1;
- float2 Tex2 : TEXCOORD2;
- float2 Tex3 : TEXCOORD3;
- };
-
-
- float3 Diffuse(float3 Normal)
- {
- float CosTheta;
- CosTheta = max(0.0f, dot(Normal, LightDirection.xyz)); // N.L Clamped
- float3 ct = (CosTheta);
- return ct; // propogate scalar result to vector
- }
-
- VS_OUTPUT VShade(VS_INPUT i, uniform int NumBones)
- {
- VS_OUTPUT o;
- float3 Pos = 0.0f;
- float3 Normal = 0.0f;
- float LastWeight = 0.0f;
-
- // Compensate for lack of UBYTE4 on Geforce3
- int4 IndexVector = D3DCOLORtoUBYTE4(i.BlendIndices);
-
- // cast the vectors to arrays for use in the for loop below
- float BlendWeightsArray[4] = (float[4])i.BlendWeights;
- int IndexArray[4] = (int[4])IndexVector;
-
- for (int iBone = 0; iBone < NumBones-1; iBone++)
- {
- LastWeight = LastWeight + BlendWeightsArray[iBone];
-
- Pos += mul(i.Pos, WorldMatrixArray[IndexArray[iBone]]) * BlendWeightsArray[iBone];
- Normal += mul(i.Normal, WorldMatrixArray[IndexArray[iBone]]) * BlendWeightsArray[iBone];
- }
- LastWeight = 1.0f - LastWeight;
-
- // Now that we have the calculated weight, add in the final influence
- Pos += (mul(i.Pos, WorldMatrixArray[IndexArray[NumBones-1]]) * LastWeight);
- Normal += (mul(i.Normal, WorldMatrixArray[IndexArray[NumBones-1]]) * LastWeight);
-
- o.Diffuse = float4(Diffuse(normalize(Normal)),1.0) + BlinkFactor;
-
- o.Tex3.xy = mul( float4(Pos.xyz, 1.0f), ShadowViewProjection ).z + ZBias.w;
- o.Tex1.xy = mul( float4(Pos.xyz, 1.0f), TextureMatrix ).xy;
-
- o.Pos = mul(float4(Pos.xyz, 1.0f), WorldMatrix);
-
- // copy the input texture coordinate through
- o.Tex0 = i.Tex0.xy;
- o.Tex2.xy = o.Pos.xz * 0.001953125; // ~ / 512
-
- o.Pos = mul(o.Pos, ViewProjection);
-
- return o;
- }
-
- int CurNumBones = 2;
- VertexShader vsArray[4] = { compile vs_1_1 VShade(1),
- compile vs_1_1 VShade(2),
- compile vs_1_1 VShade(3),
- compile vs_1_1 VShade(4)
- };
-
- VS_OUTPUT VShadeShadow(VS_INPUT i, uniform int NumBones)
- {
- VS_OUTPUT o;
- float3 Pos = 0.0f;
- float3 Normal = 0.0f;
- float LastWeight = 0.0f;
-
- // Compensate for lack of UBYTE4 on Geforce3
- int4 IndexVector = D3DCOLORtoUBYTE4(i.BlendIndices);
-
- // cast the vectors to arrays for use in the for loop below
- float BlendWeightsArray[4] = (float[4])i.BlendWeights;
- int IndexArray[4] = (int[4])IndexVector;
-
- for (int iBone = 0; iBone < NumBones-1; iBone++)
- {
- LastWeight = LastWeight + BlendWeightsArray[iBone];
-
- Pos += mul(i.Pos, WorldMatrixArray[IndexArray[iBone]]) * BlendWeightsArray[iBone];
- Normal += mul(i.Normal, WorldMatrixArray[IndexArray[iBone]]) * BlendWeightsArray[iBone];
- }
- LastWeight = 1.0f - LastWeight;
-
- // Now that we have the calculated weight, add in the final influence
- Pos += (mul(i.Pos, WorldMatrixArray[IndexArray[NumBones-1]]) * LastWeight);
- Normal += (mul(i.Normal, WorldMatrixArray[IndexArray[NumBones-1]]) * LastWeight);
-
- o.Diffuse = float4(Diffuse(normalize(Normal)),1.0) + BlinkFactor;
-
- o.Tex3.xy = mul( float4(Pos.xyz, 1.0f), ShadowViewProjection ).z;
- o.Tex1.xy = mul( float4(Pos.xyz, 1.0f), TextureMatrix ).xy;
-
- o.Pos = mul(float4(Pos.xyz, 1.0f), WorldMatrix);
-
- // copy the input texture coordinate through
- o.Tex0 = i.Tex0.xy;
- o.Tex2.xy = o.Pos.xz * 0.001953125; // ~ / 512
-
- o.Pos = mul(o.Pos, ViewProjection);
-
- return o;
- }
-
-
- VertexShader vsArrayShadow[4] = { compile vs_1_1 VShadeShadow(1),
- compile vs_1_1 VShadeShadow(2),
- compile vs_1_1 VShadeShadow(3),
- compile vs_1_1 VShadeShadow(4)
- };
-
- //////////////////////////////////////
- // Techniques specs follow
- //////////////////////////////////////
- technique Technique0
- {
- pass p0
- {
- VertexShader = (vsArray[CurNumBones]);
-
- ALPHABLENDENABLE = TRUE;
- SRCBLEND = SRCALPHA;
- DESTBLEND = INVSRCALPHA;
- ALPHATESTENABLE = FALSE;
-
- Texture[0] = (DiffuseTexture);
- Texture[1] = (FogOfWar);
- Texture[2] = (ShadowTexture);
-
- PixelShaderConstant[17] = (Ambient);
-
- PixelShader =
- asm
- {
- ps_1_4
- def c0, 1, 1, 1, 1
- def c1, 0.0, 0.0, 0.0, 0
-
- def c2, 0., 0., 0., .0 // zero
- def c3, 1.0, 1.0, 1.0, 1.0 // fog color
- def c16, 0.5, 0., 0., .0 // zero
- def c18, 10., 0., 0.1, 1.0 // ambient color
- def c19, 0.004, 0.0, 0.0, 0.0
-
- dcl t0.xy
- dcl t1.xy
- dcl t2.xy
- dcl t3.x
- dcl v0.rgba
-
- dcl_2d s0
- dcl_2d s1
- dcl_2d s2
-
- texld r1, t0, s0
- sub r2, r1.a, c16.x
- texkill r2
- texld r10, t1, s2
- // add r10.x, r10.x, c19.x //Z bias!
- sub r9.r, r10.r, t3.x
- mov r2, c1
- cmp r10, r9.r, c0, r2
-
- mad r0, r10, v0, c17
- mul r0, r1, r0
- texld r2, t2, s1
- mul r0, r2, r0
- mov r0.a, r1.a
- mov oC0, r0
- };
- }
- }
-
-
- //////////////////////////////////////
- // Techniques specs follow
- //////////////////////////////////////
- technique Technique2
- {
- pass p0
- {
- VertexShader = (vsArrayShadow[CurNumBones]);
-
- ALPHABLENDENABLE = FALSE;
- ALPHATESTENABLE = FALSE;
-
- Texture[0] = (DiffuseTexture);
-
- PixelShader =
- asm
- {
- ps_1_4
- def c16, 0.5, 0.065, 25.0, 1.0
-
- dcl t0.xy
- dcl t3.xy
- dcl v0.rgba
-
- dcl_2d s0
-
- texld r0, t0, s0
- sub r0, r0.a, c16.x
- texkill r0
- mov r0, t3.x
- mov oC0, r0
- };
- }
- }
-
-
- VS_OUTPUT VShade2( VS_INPUT i )
- {
- VS_OUTPUT o;
- float3 Pos = 0.0f;
- float3 Normal = 0.0f;
-
- o.Tex3.xy = mul( float4(i.Pos.xyz, 1.0f), ShadowViewProjection ).z + ZBias.w;
- o.Tex1.xy = mul( float4(i.Pos.xyz, 1.0f), TextureMatrix ).xy;
-
- // cast the vectors to arrays for use in the for loop below
- Pos = mul(i.Pos, WorldMatrix );
- Normal = mul(i.Normal, WorldMatrix );
-
- // transform position from world space into view and then projection space
- o.Pos = mul(float4(Pos.xyz, 1.0f), ViewProjection);
-
- o.Diffuse = float4(Diffuse(normalize(Normal)),1.0) + BlinkFactor;
-
- // copy the input texture coordinate through
- o.Tex0 = i.Tex0.xy;
- o.Tex2.xy = Pos.xz * 0.001953125;
-
- return o;
- }
-
- VS_OUTPUT VShade2Shadow( VS_INPUT i )
- {
- VS_OUTPUT o;
- float3 Pos = 0.0f;
- float3 Normal = 0.0f;
-
- // cast the vectors to arrays for use in the for loop below
- o.Tex3.xy = mul( float4(i.Pos.xyz, 1.0f), ShadowViewProjection ).z;
- o.Tex1.xy = mul( float4(i.Pos.xyz, 1.0f), TextureMatrix ).xy;
-
- Pos = mul(i.Pos, WorldMatrix );
- Normal = mul(i.Normal, WorldMatrix );
-
- // transform position from world space into view and then projection space
- o.Pos = mul(float4(Pos.xyz, 1.0f), ViewProjection);
-
- o.Diffuse = float4(Diffuse(normalize(Normal)),1.0);
-
- // copy the input texture coordinate through
- o.Tex0 = i.Tex0.xy;
- o.Tex2.xy = Pos.xz * 0.001953125;
-
- return o;
- }
-
- //////////////////////////////////////
- // Techniques specs follow
- //////////////////////////////////////
- technique Technique1
- {
- pass p0
- {
- VertexShader = compile vs_1_1 VShade2();
-
- ALPHABLENDENABLE = TRUE;
- SRCBLEND = SRCALPHA;
- DESTBLEND = INVSRCALPHA;
- ALPHATESTENABLE = FALSE;
-
- Texture[0] = (DiffuseTexture);
- Texture[1] = (FogOfWar);
- Texture[2] = (ShadowTexture);
-
- PixelShaderConstant[17] = (Ambient);
-
- PixelShader =
- asm
- {
- ps_1_4
- def c0, 1, 1, 1, 1
- def c1, 0.0, 0.0, 0.0, 0
-
- def c2, 0., 0., 0., .0 // zero
- def c3, 1.0, 1.0, 1.0, 1.0 // fog color
- def c16, 0.5, 0., 0., .0 // zero
- def c18, 10., 0., 0.1, 1.0 // ambient color
- def c19, 0.004, 0.0, 0.0, 0.0
-
- dcl t0.xy
- dcl t1.xy
- dcl t2.xy
- dcl t3.x
- dcl v0.rgba
-
- dcl_2d s0
- dcl_2d s1
- dcl_2d s2
-
- texld r1, t0, s0
- sub r2, r1.a, c16.x
- texkill r2
- texld r10, t1, s2
- // add r10.x, r10.x, c19.x //Z bias!
- sub r9.r, r10.r, t3.x
- mov r2, c1
- cmp r10, r9.r, c0, r2
-
- mad r0, r10, v0, c17
- mul r0, r1, r0
- texld r2, t2, s1
- mul r0, r2, r0
- mov r0.a, r1.a
- mov oC0, r0
- };
- }
- }
-
- //////////////////////////////////////
- // Techniques specs follow
- //////////////////////////////////////
- technique Technique3
- {
- pass p0
- {
- VertexShader = compile vs_1_1 VShade2Shadow();
-
- ALPHABLENDENABLE = FALSE;
- ALPHATESTENABLE = FALSE;
-
- Texture[0] = (DiffuseTexture);
-
- PixelShader =
- asm
- {
- ps_1_4
- def c16, 0.5, 0.065, 25.0, 1.0
-
- dcl t0.xy
- dcl t3.xy
- dcl v0.rgba
-
- dcl_2d s0
-
- texld r0, t0, s0
- sub r0, r0.a, c16.x
- texkill r0
- mov r0, t3.x
- mov oC0, r0
- };
- }
- }
-